package com.kzj.controller;


import com.kzj.domain.Administrator;
import com.kzj.domain.Student;
import com.kzj.domain.Teacher;
import com.kzj.domain.vo.ForbiddenVO;
import com.kzj.global.constant.GlobalConstant;
import com.kzj.global.exception.MyException;
import com.kzj.global.re.Result;
import com.kzj.global.threadLocal.UserThreadLocal;
import com.kzj.global.utils.GlobalUtil;
import com.kzj.service.AdministratorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kzj
 * @since 2023-12-01
 */
@RestController
@RequestMapping("/administrator")
@Api(tags = "管理员相关接口")
public class AdministratorController {
    @Autowired
    AdministratorService administratorService;
    @ModelAttribute
    public void modelAttribute() {
        String type = UserThreadLocal.getType();
        if(!type.equals(GlobalConstant.ADMINISTRATOR_TYPE))
            throw new MyException(GlobalConstant.USER_PERMISSION_DENIED);
    }
    @ApiOperation("获取所有学院")
    @GetMapping("/getAllAcademy")
    public Result getAllAcademy()
    {
        return administratorService.getAllAcademy();
    }
    @ApiOperation("获取某学院的所有专业")
    @GetMapping("/getMajorByAcademyId/{academyId}")
    public Result getMajorByAcademyId(@PathVariable String academyId)
    {
        return administratorService.getMajorByAcademyId(academyId);
    }
    @ApiOperation("获取某专业的所有班级")
    @GetMapping("/getClassByMajorId")
    public Result getClassByMajorId(String majorId,Integer period)
    {
        return administratorService.getClassByMajorIdAndPeriod(majorId,period);
    }
    @ApiOperation("获取某班级的学生")
    @GetMapping("/getStudentByStudentClassId/{studentClassId}")
    public Result getStudentByStudentClassId(@PathVariable String studentClassId)
    {
        return administratorService.getStudentByStudentClassId(studentClassId);
    }
    @ApiOperation("获取某个专业的学生")
    @GetMapping("/getStudentByMajorId/{majorId}")
    public Result getStudentByMajorId(@PathVariable String majorId)
    {
        return administratorService.getStudentByMajorId(majorId);
    }
    @ApiOperation("获取某个学院的学生")
    @GetMapping("/getStudentByAcademyId/{academyId}")
    public Result getStudentByAcademyId(@PathVariable String academyId)
    {
        return administratorService.getStudentByAcademyId(academyId);
    }
    @ApiOperation("获取某个学院的老师")
    @GetMapping("/getTeacherByAcademyId/{academyId}")
    public Result getTeacherByAcademyId(@PathVariable String academyId)
    {
        return administratorService.getTeacherByAcademyId(academyId);
    }
    @ApiOperation("获取所有的老师")
    @GetMapping("/getAllTeacher")
    public Result getAllTeacher()
    {
        return administratorService.getAllTeacher();
    }
    @ApiOperation("通过id获取学生的信息")
    @GetMapping("/getStudentById/{studentId}")
    public Result getStudentById(@PathVariable String studentId)
    {
        return administratorService.getStudentById(studentId);
    }
    @ApiOperation("添加学生")
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody Student student)
    {
        return administratorService.addStudent(student);
    }
    @ApiOperation("添加老师")
    @PostMapping("/addTeacher")
    public Result addTeacher(@RequestBody Teacher teacher)
    {
        return administratorService.addTeacher(teacher);
    }
    @ApiOperation("通过id查看学生当前学期的选课")
    @GetMapping("/getStudentCurrentTermSchedule/{studentId}")
    public Result getStudentCurrentTermSchedule(@PathVariable String studentId)
    {
        return administratorService.getStudentCurrentTermSchedule(studentId);
    }
    @ApiOperation("通过id查看学生下学期的课表")
    @GetMapping("/getStudentNextTermSchedule/{studentId}")
    public Result getStudentNextSchedule(@PathVariable String studentId)
    {
        return administratorService.getStudentNextTermSchedule(studentId);
    }
    @ApiOperation("通过id和term查看学生的课表")
    @GetMapping("/getStudentSchedule")
    public Result getStudentSchedule(String studentId,Integer term)
    {
        return administratorService.getStudentSchedule(studentId,term);
    }
    @ApiOperation("通过id查看老师的信息")
    @GetMapping("/getTeacherById/{teacherId}")
    public Result getTeacherById(@PathVariable String teacherId)
    {
        return administratorService.getTeacherById(teacherId);
    }
    @ApiOperation("通过id和curriculum_time获取老师某学期安排的课程")
    @GetMapping("/getTeacherSchedule")
    public Result getTeacherSchedule(String teacherId,String  curriculumTime)
    {
        return administratorService.getTeacherSchedule(teacherId,curriculumTime);
    }@ApiOperation("通过id获取老师当前学期安排的课程列表")
    @GetMapping("/getTeacherCurrentTermSchedule/{teacherId}")
    public Result getTeacherCurrentTermSchedule(@PathVariable String teacherId)
    {
        return administratorService.getTeacherCurrentTermSchedule(teacherId);
    }
    @ApiOperation("通过id获取老师下学期安排的课程列表")
    @GetMapping("/getTeacherNextTermSchedule/{teacherId}")
    public Result getTeacherNextTermSchedule(@PathVariable String teacherId)
    {
        return administratorService.getTeacherNextTermSchedule(teacherId);
    }
    @ApiOperation("通过id禁用学生")
    @PostMapping("/forbiddenStudent")
    public Result forbiddenStudent(@RequestBody ForbiddenVO forbiddenVO)
    {
        return administratorService.forbiddenStudent(forbiddenVO);
    }
    @ApiOperation("通过id禁用老师")
    @PostMapping("/forbiddenTeacherId")
    public Result forbiddenTeacher(@RequestBody ForbiddenVO forbiddenVO)
    {
        return administratorService.forbiddenTeacher(forbiddenVO);
    }
    @ApiOperation("结束抢课（下学期的课程）")
    @PostMapping("/stopRobClasses")
    public Result stopRobClasses()
    {
        return administratorService.stopRobClasses();
    }
    @ApiOperation("设定结束抢课的时间（下学期的课程）")
    @PutMapping("/setStopRobClassesDateTime")
    public Result setStopRobClassesDateTime(@DateTimeFormat(pattern = GlobalConstant.DATE_TIME_FORMATTER) LocalDateTime dateTime)
    {
        return administratorService.stopRobClasses(dateTime);
    }
    @ApiOperation("开始抢课（下学期的课程）")
    @PostMapping("/startNextTermRobClasses")
    public Result startNextTermRobClasses()
    {
        return administratorService.startNextTermRobClasses();
    }
    @ApiOperation("设定开始抢课的时间（下学期的课程）")
    @PutMapping("/setStartNextTermRobClassesDateTime")
    public Result  setStartNextTermRobClassesDateTime(@DateTimeFormat(pattern = GlobalConstant.DATE_TIME_FORMATTER) LocalDateTime dateTime)
    {
        return administratorService.startNextTermRobClasses(dateTime);
    }
    @ApiOperation("安排考试（下学期的课程）")
    @PostMapping("/arrangeExamination")
    public Result arrangeExamination()
    {
        return administratorService.arrangeExamination();
    }
    @ApiOperation("设定安排考试的时间（下学期的课程）")
    @PutMapping("/setArrangeExaminationDateTime")
    public Result setArrangeExaminationDateTime(@DateTimeFormat(pattern = GlobalConstant.DATE_TIME_FORMATTER) LocalDateTime dateTime)
    {
        return administratorService.arrangeExamination(dateTime);
    }
    @ApiOperation("通过id获得老师本学期的课表")
    @GetMapping("/getCurrentTermScheduleList/{teacherId}")
    public Result getCurrentTermSchedule(@PathVariable String teacherId)
    {
        return administratorService.getCurrentTermScheduleList(teacherId);
    }
    @ApiOperation("通过id获得老师下学期的课表")
    @GetMapping("/getNextTermScheduleList/{teacherId}")
    public Result getNextTermSchedule(@PathVariable String teacherId)
    {
        return administratorService.getNextTermScheduleList(teacherId);
    }
    @ApiOperation("修改学生信息")
    @PostMapping("/updateStudentInfo")
    public Result updateStudentInfo(@RequestBody Student student)
    {
        return administratorService.updateStudentInfo(student);
    }
    @ApiOperation("修改老师信息")
    @PostMapping("/updateTeacherInfo")
    public Result updateTeacherInfo(@RequestBody Teacher teacher)
    {
        return administratorService.updateTeacherInfo(teacher);
    }

}

